extends modelsim
extends vivadotcl

#########################################################################

snippet if "if-else"
if { "abc" == "abc" } {
    puts "nihao"
} else {
    puts "world"
}
endsnippet

snippet switch "switch" b
switch ${1:\$var} {
	${2:str1} {
		$3
	}
	default {
		puts "invalid grade"
	}
}
endsnippet

snippet while "while loop" b
while { ${1:bool} } {
	$2
}
endsnippet

snippet for "for loop" b
for {${1:set a 10}} {${2:\$a < 20}} {incr ${3:a}} {
	$4
}
endsnippet


snippet list_create "create list" w
set color {red blue green}
set color [list red blue green]
endsnippet

snippet list_concat "concat list" w
concat ${1:list1} ${2:list2}
endsnippet

snippet list_index "Retrieve an element from a list" w
lindex ${1:list} ${2:index}
endsnippet

snippet list_repeat "Description" w
list_repeat ${1:list} ${2:count}
endsnippet

snippet list_length "Count the number of elements in a list" w
llength ${1:list}
endsnippet

snippet list_range "Return one or more adjacent elements from a list" w
lrange ${1:list} ${2:start} ${3:stop}
endsnippet

snippet list_assign "Description" w
lassign ${1:old_list} ${2:new_list} ${3:start} ${4:stop}
endsnippet

snippet list_append "Append list elements onto a variable" w
lappend ${1:list} ${2:element}
endsnippet

snippet list_insert "Insert elements into a list" w
linsert ${1:list} ${2:position} ${3:element}
endsnippet

snippet list_replace "Replace elements in a list with new elements" w
lreplace ${1:list} ${2:start} ${3:stop}
endsnippet

snippet list_search "See if a list contains a particular element" w
lsearch -exact ${1:list} ${2:value}
endsnippet

snippet list_join "Create a string by joining together list elements" w
join ${1:list} ${2:separator}
endsnippet

snippet list_foreach "use foreach to iterate list" !b
set ${1:list_name} {44 55 ee}
for {set i 0} { \$i < [llength \$$1] } {incr i} {
    mem load -filltype value -filldata [lindex \$$1 \$i] -fillradix hexadecimal /ms5837_tb/ms5837_topEx01/ms5837_romEx01/inst/ram_data(\$i)
}

endsnippet

snippet foreach "foreach loop" w
foreach ${1:var} ${2:list} {
	$3
}
endsnippet


snippet str_compare "compare string1 string2" w
string compare ${1:str1} ${2:str2}
endsnippet

snippet str_match "if pattern matches string; return 1" b
string match ${1:pattern} ${2:string}
endsnippet

snippet str_index "Returns the charIndex'th character of the string argument" w
string index ${1:string} ${2:charIndex}
endsnippet

snippet str_last "Search string2 for a sequence of characters that exactly match the characters in string1" w
string last ${1:e} ${2:hello}
endsnippet

snippet str_length "Returns a decimal string giving the number of characters in string" w
string length ${1:string}
endsnippet

snippet str_range "Returns a range of consecutive characters from string" w
string range ${1:string} ${2:startIndex} ${3:endIndex}
endsnippet

snippet str_tolower "" w
string tolower ${1:string}
endsnippet

snippet str_toupper "" w
string toupper ${1:string}
endsnippet

snippet str_trim "remove any leading or trailing characters" w
string trim ${1:string}
endsnippet

snippet str_repeat "Returns string repeated count number of times" w
string repeat ${1:string} ${2:count}
endsnippet

snippet regsub "Perform substitutions based on regular expression pattern matching" b
regsub ${1:exp1} ${2:source} ${3:exp2} ${4:?valName?}
endsnippet

snippet regexp "Description" !b
regexp {(${1:\d{4}})} ${2:"Hello 2021"} match ${3:ouput_name}
puts $$3
endsnippet

snippet proc "Description" w
# add 10 20
proc ${1:add} {${2:a} ${3:b}} {
	return ${4:\$a + \$b};
}
endsnippet



snippet file_copy "copy the file or directory  to target" w
file copy $1
endsnippet

snippet file_delete "Removes the file or directory(-force)" w
file delete ${1:name}
endsnippet

snippet file_dirname "" w
$1
endsnippet

snippet file_executable "Returns 1 if file name is executable" w
file executable ${1:filename}
endsnippet

snippet file_exists "Returns 1 if file name exists" w
file exists ${1:filename}
endsnippet

snippet file_extension "return the extension of file" w
file extension ${1:filename}
endsnippet

snippet file_isdirectory "Returns 1 if file name is a directory" w
file isdirectory ${1:path}
endsnippet

snippet file_isfile "Returns 1 if file name is a regular file" w
file isfile ${1:filename}
endsnippet

snippet file_join "Takes one or more file names and combines them" w

endsnippet

snippet file_mkdir "Creates each directory specified" w
file mkdir ${1:dir}
endsnippet

snippet file_rename "renames source to target" w
file rename ${1:source} ${2:target}
endsnippet

snippet file_rootname "return the root of file" w
file rootname ${1:filename}
endsnippet

snippet file_separator "returns the character used to separate path" w
file separator
endsnippet

snippet file_size "Returns a decimal string giving the size of file name in bytes" w
file size ${1:filename}
endsnippet

snippet file_split "Returns a list whose elements are the path component" w
file split ${1:path}
endsnippet

snippet file_tail "Returns all of the characters after the last directory separator" w
file tail ${1:path}
endsnippet

snippet file_open "open file and print all data" w
set file_path  ""
set fp [open $file_path r]

while { [gets $fp line] >= 0 } {
    puts $line
}
close $fp
endsnippet

snippet load_lib "source user functions" b
source "$env(HOME)/tcl/sim.tcl"
endsnippet


snippet array_create "create array"
array set ms5837_flow {0 22 1 33 2 ff}
# or
endsnippet

snippet dir_pwd "The directory where the script resides"
set script_path [ file dirname [ file normalize [ info script ] ] ]
set parent_directory [ file dirname $script_path ]
set grandparent_directory [ file dirname $parent_directory ]
endsnippet
